﻿package mortal.game.manager
{
    import Framework.Util.*;
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import com.gengine.debug.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.display.*;
    import mortal.common.error.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.ai.ais.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.copy.groupCopy.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class MsgManager extends Object
    {
        private static var _msgBroadImpl:MsgBroadCastImpl;
        private static var _msgTipImpl:MsgTipTextImpl;
        private static var _msgSpeakerImpl:MsgSpeakerImpl = new MsgSpeakerImpl();
        private static var _msgFloatWordImpl:MsgFloatWordImpl;
        private static var _msgTaskShowImpl:MsgTaskShowImpl;
        private static var _msgCopyTaskEndImpl:MsgCopyTaskEndImpl;
        private static var _msgRollRadioImpl:MsgRollRadioImpl;
        private static var _msgRollTipsImpl:MsgRollTipsBmpImpl;
        private static var _msgFightTipsImpl:MsgFightTipBmpImpl;
        private static var _msgGuideTipsImpl:MsgGuideTipsImpl;
        private static var _msgSceneInfo:MsgSceneInfoImpl;
        private static var _msgPlotInfo:MsgPlotShowImpl;
        private static var _msgMouseInfo:MsgMouseInfoImpl;

        public function MsgManager()
        {
            return;
        }// end function

        private static function get msgBroadImpl() : MsgBroadCastImpl
        {
            var _loc_1:* = new MsgBroadCastImpl();
            _msgBroadImpl = new MsgBroadCastImpl();
            return _msgBroadImpl || _loc_1;
        }// end function

        private static function get msgTipImpl() : MsgTipTextImpl
        {
            var _loc_1:* = new MsgTipTextImpl();
            _msgTipImpl = new MsgTipTextImpl();
            return _msgTipImpl || _loc_1;
        }// end function

        private static function get msgFloatWordImpl() : MsgFloatWordImpl
        {
            var _loc_1:* = new MsgFloatWordImpl();
            _msgFloatWordImpl = new MsgFloatWordImpl();
            return _msgFloatWordImpl || _loc_1;
        }// end function

        private static function get msgTaskShowImpl() : MsgTaskShowImpl
        {
            var _loc_1:* = new MsgTaskShowImpl();
            _msgTaskShowImpl = new MsgTaskShowImpl();
            return _msgTaskShowImpl || _loc_1;
        }// end function

        private static function get msgCopyTaskEndImpl() : MsgCopyTaskEndImpl
        {
            var _loc_1:* = new MsgCopyTaskEndImpl();
            _msgCopyTaskEndImpl = new MsgCopyTaskEndImpl();
            return _msgCopyTaskEndImpl || _loc_1;
        }// end function

        private static function get msgRollRadioImpl() : MsgRollRadioImpl
        {
            var _loc_1:* = new MsgRollRadioImpl();
            _msgRollRadioImpl = new MsgRollRadioImpl();
            return _msgRollRadioImpl || _loc_1;
        }// end function

        public static function get msgRollTipsImpl() : MsgRollTipsBmpImpl
        {
            var _loc_1:* = new MsgRollTipsBmpImpl();
            _msgRollTipsImpl = new MsgRollTipsBmpImpl();
            return _msgRollTipsImpl || _loc_1;
        }// end function

        public static function get msgFightTipsImpl() : MsgFightTipBmpImpl
        {
            var _loc_1:* = new MsgFightTipBmpImpl();
            _msgFightTipsImpl = new MsgFightTipBmpImpl();
            return _msgFightTipsImpl || _loc_1;
        }// end function

        private static function get msgGuideTipsImpl() : MsgGuideTipsImpl
        {
            var _loc_1:* = new MsgGuideTipsImpl();
            _msgGuideTipsImpl = new MsgGuideTipsImpl();
            return _msgGuideTipsImpl || _loc_1;
        }// end function

        private static function get msgSceneInfo() : MsgSceneInfoImpl
        {
            var _loc_1:* = new MsgSceneInfoImpl();
            _msgSceneInfo = new MsgSceneInfoImpl();
            return _msgSceneInfo || _loc_1;
        }// end function

        private static function get msgPlotInfo() : MsgPlotShowImpl
        {
            var _loc_1:* = new MsgPlotShowImpl();
            _msgPlotInfo = new MsgPlotShowImpl();
            return _msgPlotInfo || _loc_1;
        }// end function

        private static function get msgMouseInfo() : MsgMouseInfoImpl
        {
            var _loc_1:* = new MsgMouseInfoImpl();
            _msgMouseInfo = new MsgMouseInfoImpl();
            return _msgMouseInfo || _loc_1;
        }// end function

        public static function addBroadStage(param1:ILayer) : void
        {
            msgBroadImpl.layer = param1;
            return;
        }// end function

        public static function addTipStage(param1:DisplayObjectContainer) : void
        {
            param1.addChild(msgTipImpl);
            return;
        }// end function

        public static function addSpeakerStage(param1:DisplayObjectContainer) : void
        {
            param1.addChild(_msgSpeakerImpl);
            return;
        }// end function

        public static function resize() : void
        {
            msgBroadImpl.stageResize();
            msgTipImpl.stageResize();
            _msgSpeakerImpl.setPxy();
            msgFloatWordImpl.stageResize();
            msgTaskShowImpl.stageResize();
            msgCopyTaskEndImpl.stageResize();
            msgRollRadioImpl.stageResize();
            msgRollTipsImpl.stageResize();
            msgFightTipsImpl.stageResize();
            msgSceneInfo.stageReseze();
            msgPlotInfo.stageReseze();
            return;
        }// end function

        public static function chatResize() : void
        {
            _msgSpeakerImpl.setPxy();
            return;
        }// end function

        public static function addBroadCast(param1:Object, param2:MsgTypeImpl = null) : void
        {
            if (param1 == null)
            {
                return;
            }
            param2 = param2 == null ? (MsgType.DefaultMsg) : (param2);
            msgBroadImpl.showNotice(param1.toString());
            return;
        }// end function

        public static function showHideTipText(param1:Boolean) : void
        {
            if (_msgTipImpl)
            {
                if (_msgTipImpl.parent && !param1)
                {
                    _msgTipImpl.parent.removeChild(_msgTipImpl);
                }
                else if (!_msgTipImpl.parent && param1)
                {
                    LayerManager.uiLayer.addChildAt(_msgTipImpl, 0);
                }
            }
            return;
        }// end function

        public static function addTipText(param1:String, param2:MsgTypeImpl) : void
        {
            if (param1 == null)
            {
                return;
            }
            if (param1 == null)
            {
                return;
            }
            param2 = param2 == null ? (MsgType.DefaultMsg) : (param2);
            _msgTipImpl.showInfo(param1.toString(), param2.color, param2.delay);
            GameController.sysHistory.addHistroy(param1, param2);
            return;
        }// end function

        public static function addSpeakerText(param1:SMiniPlayer, param2:String, param3:MsgTypeImpl = null) : void
        {
            if (param1 == null)
            {
                return;
            }
            param3 = param3 == null ? (MsgType.DefaultMsg) : (param3);
            _msgSpeakerImpl.showSpeakerNotice(param1, param2, param3);
            return;
        }// end function

        public static function removeSpeakByEntityId(param1:SEntityId) : void
        {
            _msgSpeakerImpl.removeSpeakerNotice(param1);
            return;
        }// end function

        public static function addFloatWord(param1:Object, param2:MsgTypeImpl = null) : void
        {
            if (param1 == null)
            {
                return;
            }
            param2 = param2 == null ? (MsgType.DefaultMsg) : (param2);
            msgFloatWordImpl.showWord(param1.toString());
            return;
        }// end function

        public static function removeFloatWord() : void
        {
            msgFloatWordImpl.dispose();
            return;
        }// end function

        public static function showTaskTarget(param1:String, param2:int = 5) : void
        {
            if (!param1)
            {
                return;
            }
            msgTaskShowImpl.showTarget(param1, param2);
            return;
        }// end function

        public static function removeTaskTarget() : void
        {
            msgTaskShowImpl.hide();
            return;
        }// end function

        public static function get taskTargetTxt() : String
        {
            return msgTaskShowImpl.currentShowTxt;
        }// end function

        public static function showRollRadioMsg(param1:String, param2:int = 3, param3:int = 2, param4:Boolean = false) : void
        {
            if (param1 == null || param1 == "")
            {
                return;
            }
            msgRollRadioImpl.showMsg(param1, param2, param3, param4);
            return;
        }// end function

        public static function hideRollRadioMsg() : void
        {
            msgRollRadioImpl.hide();
            return;
        }// end function

        public static function showRollTipsMsg(param1:String, param2:MsgRollTipsType = null, param3:Boolean = false) : void
        {
            if (param1 == null || param1 == "")
            {
                return;
            }
            if (!param2)
            {
                param2 = MsgRollTipsType.msgRollTips1;
            }
            msgRollTipsImpl.showMsg(param1, param2, param3);
            return;
        }// end function

        public static function showFightTipsImpl(param1:String, param2:MsgRollTipsType = null, param3:Boolean = false) : void
        {
            if (param1 == null || param1 == "")
            {
                return;
            }
            if (!param2)
            {
                param2 = MsgRollTipsType.msgRollTips5;
            }
            msgFightTipsImpl.showMsg(param1, param2, param3);
            return;
        }// end function

        public static function showMouseMsg(param1:String, param2:MsgRollTipsType = null, param3:int = 50, param4:int = -13) : void
        {
            if (!param2)
            {
                param2 = MsgRollTipsType.msgRollTips1;
            }
            showRollTipsMsg(param1, param2);
            return;
        }// end function

        public static function showGuideTips(param1:String, param2:int, param3:int, param4:DisplayObjectContainer = null, param5:int = 0) : void
        {
            msgGuideTipsImpl.show(param1, param2, param3, param4, param5);
            return;
        }// end function

        public static function hideGuideTips() : void
        {
            msgGuideTipsImpl.hide();
            return;
        }// end function

        public static function showCopyEndStr(param1:String, param2:int, param3:int, param4:Function = null) : void
        {
            msgCopyTaskEndImpl.show(param1, param2, param3, param4);
            return;
        }// end function

        public static function hideCopyEndStr() : void
        {
            msgCopyTaskEndImpl.hide();
            return;
        }// end function

        public static function showSceneDes(param1:String, param2:Array) : void
        {
            if (param1 && param2 && param1 != "" && param2.length > 0)
            {
                msgSceneInfo.showMsg(param1, param2);
            }
            return;
        }// end function

        public static function hideSceneDes() : void
        {
            msgSceneInfo.hideMsg();
            return;
        }// end function

        public static function showPlotMsg(param1:String, param2:Function = null) : void
        {
            msgPlotInfo.showMsg(param1, param2);
            return;
        }// end function

        public static function hidePlotMsg() : void
        {
            msgPlotInfo.hideMsg();
            return;
        }// end function

        public static function alertError(param1:int) : void
        {
            Alert.show(Language.getStringByParam(20490, param1, ErrorCode.getErrorStringByCode(param1)), Language.getString(20495));
            return;
        }// end function

        public static function alertIssm(param1:String) : void
        {
            return;
        }// end function

        public static function addChatMsg(param1:Object, param2:String) : void
        {
            return;
        }// end function

        public static function systemError(param1:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_5:Exception = null;
            var _loc_6:SErrorMsg = null;
            var _loc_3:String = "";
            var _loc_4:String = "";
            if (param1 is Exception)
            {
                _loc_5 = param1 as Exception;
                _loc_2 = _loc_5.code;
                _loc_3 = _loc_5.message;
                _loc_4 = Language.getStringByParam(20491, _loc_5.method, _loc_5.code);
                rmiCallback(_loc_5);
            }
            else if (param1 is SErrorMsg)
            {
                _loc_6 = param1 as SErrorMsg;
                _loc_2 = _loc_6.code;
                _loc_3 = _loc_6.message;
                _loc_4 = Language.getStringByParam(20492, param1.code);
                errorCallback(_loc_6);
            }
            showErrorByCode(_loc_2, _loc_4, _loc_3);
            return;
        }// end function

        public static function showErrorByCode(param1:int, param2:String = "", param3:String = "") : void
        {
            var code:* = param1;
            var errorStr:* = param2;
            var msg:* = param3;
            var errorCode:* = ErrorCodeConfig.instance.getInfoByCode(code);
            if (!msg)
            {
                msg = errorCode.errorStr;
            }
            if (errorCode)
            {
                if (!errorCode.isOnlyIntranetShow || Global.isDebugModle)
                {
                    addTips(errorStr, msg, errorCode.display);
                }
            }
            else
            {
                addTips(errorStr, ErrorCode.getErrorStringByCode(code), 0);
            }
            if (code == 36520)
            {
                var closeAlert:* = function (param1:int) : void
            {
                var _loc_2:GroupCopyLeaveOperData = null;
                if (param1 == Alert.OK)
                {
                    _loc_2 = new GroupCopyLeaveOperData();
                    _loc_2.isShowAler = false;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupLeave, _loc_2));
                }
                return;
            }// end function
            ;
                Alert.show(Language.getString(20493), null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            }
            return;
        }// end function

        private static function sendErrorMsgCount(param1:String, param2:int) : void
        {
            var onEnterFrameHandler:Function;
            var value:* = param1;
            var num:* = param2;
            onEnterFrameHandler = function (param1:SecTimer) : void
            {
                MsgManager.addBroadCast(value);
                return;
            }// end function
            ;
            var timer:* = new SecTimer(1, num);
            timer.addListener(TimerType.ENTERFRAME, onEnterFrameHandler);
            timer.start();
            return;
        }// end function

        private static function addTips(param1:String, param2:String, param3:int) : void
        {
            if (Global.isDebugModle)
            {
                param1 = Language.getStringByParam(20494, param1, param2);
            }
            else
            {
                if (param3 == 0)
                {
                    return;
                }
                param1 = param2;
            }
            if (param3 & EShowArea._EShowAreaChat)
            {
            }
            if (param3 & EShowArea._EShowAreaHistory)
            {
                MsgManager.addTipText(param1, MsgHistoryType.FightMsg);
            }
            if (param3 & EShowArea._EShowAreaMiddle)
            {
                MsgManager.addBroadCast(param1);
            }
            if (param3 & EShowArea._EShowAreaRightDown || param3 & EShowArea._EShowAreaRollShow)
            {
                MsgManager.showRollTipsMsg(param1);
            }
            if (param3 & EShowArea._EShowAreaCursor)
            {
                MsgManager.showMouseMsg(param1, MsgRollTipsType.msgRollTips4);
            }
            return;
        }// end function

        private static function errorCallback(param1:SErrorMsg) : void
        {
            var _loc_2:int = 0;
            var _loc_3:ICDData = null;
            switch(param1.code)
            {
                case ErrorCode.ErrorPublic_SkillCDNotEnd:
                {
                    _loc_2 = int(param1.message);
                    if (AutoFightAI.isWorking)
                    {
                        _loc_3 = Cache.instance.cd.getCDDataByKeyType(CDDataType.skillInfo, _loc_2.toString());
                        if (_loc_3 != null && !_loc_3.isCoolDown)
                        {
                            _loc_3.startCoolDown();
                        }
                    }
                    break;
                }
                case ErrorCode.ErrorPublic_BossTooFar:
                {
                    ThingUtil.selectEntity = null;
                    break;
                }
                case ErrorCode.ErrorPublic_CollectStoped:
                {
                    if (AutoFightAI.isWorking)
                    {
                        Log.error(Language.getString(20496));
                        AutoFightAI.instance.stopCurCollect();
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private static function rmiCallback(param1:Exception) : void
        {
            switch(param1.code)
            {
                case ErrorCode.ErrorGate_TransportHadTask:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public static function get rollMsgLength() : int
        {
            return msgRollTipsImpl.msgLength;
        }// end function

    }
}
